<template>
  <div class="fillcontain" v-loading="loading">
    <bt-col-header title="模型管理"></bt-col-header>
    <div class="page-content">
      <el-form :model="dataForm" @keyup.enter.native="getDataList()" class="" label-width="120px">
        <el-form-item label="模型名称"  class="col-md-6">
          <el-input v-model="dataForm.entityName" placeholder="模型名称" clearable></el-input>
        </el-form-item>
        <el-form-item label="模型标识"  class="col-md-6">
          <el-input v-model="dataForm.entityIdentify" placeholder="模型标识" clearable></el-input>
        </el-form-item>
        <div class="row contain-padding">
          <div class="col-md-12 text-center mt-2">
            <rich-button :plain="true" type="info" shape="capsule" icon='search' @click="getDataList()">查询</rich-button>
            <!-- <rich-button  v-if="isAuth('entity:sync')" shape="capsule" icon='quit' @click="syncData">同步</rich-button> -->
          </div>
        </div>
      </el-form>

      <div class="">
        <!-- 操作按钮 -->
        <div class="btn-padding left">
          <el-button :plain="true" type="info" icon="circle-plus" @click="editInfo()">新增</el-button>
        </div>
        <!-- 查询结果列表 -->
        <div class="table_container">
          <!-- 列表 -->
          <el-table
            :data="dataList"
            border
            style="width: 100%; ">
            <el-table-column
              type="index"
              header-align="center"
              width="50"
              label="序号">
            </el-table-column>
            <el-table-column
              prop="entityName"
              header-align="center"
              align="center"
              label="模型名称">
            </el-table-column>
            <el-table-column
              prop="entityIdentify"
              header-align="center"
              align="center"
              label="模型标识">
            </el-table-column>
            <el-table-column
              prop="pkgName"
              header-align="center"
              align="center"
              label="包路径">
            </el-table-column>
            <el-table-column
              prop="entityDesc"
              header-align="center"
              align="center"
              label="模型说明">
            </el-table-column>

            <el-table-column
              header-align="center"
              align="center"
              label="操作">
              <template slot-scope="scope">
                <el-button v-if="isAuth('entity:view')" type="text" size="small" @click="viewInfo(scope.row.entityId)">查看
                </el-button>
                <!--          <el-button v-if="isAuth('entity:sync')" type="text" size="small" @click="sycnByEntityId(scope.row.entityId)">同步</el-button>-->
                <el-button v-if="isAuth('entity:sync')" type="text" size="small" @click="editInfo(scope.row.entityId)">编辑
                </el-button>
                <!--          <el-button v-if="isAuth('entity:del')" type="text" size="small" @click="deleteHandle(scope.row.entityId)">删除</el-button>-->
              </template>
            </el-table-column>
          </el-table>

          <!-- 分页 -->
          <el-pagination
            class="float-right mt-2"
            @size-change="sizeChangeHandle"
            @current-change="currentChangeHandle"
            :current-page="page.pageIndex"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="page.pageSize"
            :total="page.totalPage"
            layout="total, sizes, prev, pager, next, jumper">
          </el-pagination>
        </div>

      </div>
    </div>
    


  </div>
</template>

<script>
    import {pageList, sycnEntityData, sycnByEntity} from '@/api/baseConfig/entity'
    import constant from "../../../../../api/constant";

    export default {
        data() {
            return {
                loading: false,
                viewVisible: false,
                dataForm: {
                    entityName: '',
                    entityIdentify: ''
                },
                dataList: [],
                dataListLoading: false,
                addOrUpdateVisible: false,
                page: {
                    pageIndex: 1,
                    pageSize: 10,
                    totalPage: 0
                }
            }
        },
        components: {
        },
        activated() {
            this.getDataList()
        },
        methods: {
            syncData() {
                this.$store.dispatch('loading/CHANGE_LOADING', true)
                let params = {}
                sycnEntityData(params).then(res => {
                    this.$store.dispatch('loading/CHANGE_LOADING', false)
                    if (res.data && res.data.resultCode === 0) {
                        this.getDataList()
                    }else{
                        this.$message.error(res.data.resultMsg)
                    }

                }).catch(err=>{
                    this.$store.dispatch('loading/CHANGE_LOADING', false)
                })
            },
            sycnByEntityId(id) {
                let params = {
                    id: id + ''
                }
                sycnByEntity(params).then(res => {

                })
            },
            // 每页数
            sizeChangeHandle(val) {
                this.page.pageSize = val
                this.page.pageIndex = 1
                this.getDataList()
            },
            // 当前页
            currentChangeHandle(val) {
                this.page.pageIndex = val
                this.getDataList()
            },
            // 获取数据列表
            getDataList() {
                this.$store.dispatch('loading/CHANGE_LOADING', true)
                let params = {
                    pageNumber: this.page.pageIndex,
                    pageSize: this.page.pageSize,
                    entityName: this.dataForm.entityName,
                    entityIdentify: this.dataForm.entityIdentify
                }
                pageList(params).then(res => {
                    this.$store.dispatch('loading/CHANGE_LOADING', false)
                    this.dataList = res.data.data.list
                    this.page.totalPage = res.data.data.totalCount
                }).catch(err=>{
                    this.$store.dispatch('loading/CHANGE_LOADING', false)
                })
            },
            // 新增 / 修改
            editInfo(id) {
                constant.clearTag(this)
              if(id){
                  this.$router.push({path: "/drools-baseConfig/entity/add-or-update/"+id,query:{isEdit:true}})
              }else{
                  this.$router.push({path: "/drools-baseConfig/entity/add-or-update"  })
              }
            },
            viewInfo(id) {
                constant.clearTag(this)
                this.$router.push({path: "/drools-baseConfig/entity/view-entity/"+id,query:{isView:true}})
            },
            // 删除
            deleteHandle(id) {
                this.$confirm(`确定对[id=${id}]进行[删除]操作?`, '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    let params = {
                        id: id + ''
                    }
                    del(params).then(res => {
                        if (res.data && res.data.resultCode === 0) {
                            this.$message({
                                message: '操作成功',
                                type: 'success',
                                duration: 1500,
                                onClose: () => {
                                    this.getDataList()
                                }
                            })
                        } else {
                            this.$message.error(res.data.resultMsg)
                        }
                    })
                }).catch(() => {
                })
            }
        }
    }
</script>

<style lang="less" scoped>

</style>
